﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace NAutoForm.utils
{
    public class PhoneNumberUtils
    {
        public static string GetRandomPhoneNumber()
        {
            bool foundMatch = false;
            string strReturn = string.Empty;
            Random random = new Random();//随机数
            strReturn = "1";
            for (int i = 0; i < 10; i++)
            {
                int intRandom;
                if (i == 0)
                {
                    intRandom = random.Next(3, 8);//产生一个3-8随机整数
                }
                else
                {
                    intRandom = random.Next(0, 9);//产生一个0-9随机整数
                }
                if (strReturn.Substring(1) == "6")//截取第二个元素
                {
                    intRandom = 6;
                }
                if (strReturn.Substring(1) == "4")
                {
                    intRandom = 7;
                }
                strReturn += intRandom.ToString();
            }
            foundMatch = Regex.IsMatch(strReturn, @"^(13[0-9]|147|15[0-9]|166|17[0-9]|18[0-9])\d{8}$");//正则匹配手机号码的格式

            return strReturn;
        }
    }
}
